#pragma once
#include <pthread.h>
#include <unistd.h>
#include "Mutex.hpp"
#include <iostream>
using namespace MutexModule;
namespace CondModule
{
    class Cond
    {
    public:
        Cond()
        {
            pthread_cond_init(&_cond, nullptr);
        }
        void Wait(Mutex &mutex)
        {
            int n = pthread_cond_wait(&_cond, mutex.GetMutexPtr());
            (void)n;
        }
        void Signal()
        {
            int n = pthread_cond_signal(&_cond);
            (void)n;
        }
        void Broadcast() // 唤醒所有条件变量下等待线程
        {
            int n = pthread_cond_broadcast(&_cond);
            (void)n;
        }
        ~Cond() { pthread_cond_destroy(&_cond); }

    private:
        pthread_cond_t _cond;
    };
};
